package com.hyy.springbootblog.controller;

import com.hyy.springbootblog.common.pojo.request.UserLoginParam;
import com.hyy.springbootblog.common.pojo.response.UserInfoResponse;
import com.hyy.springbootblog.common.pojo.response.UserLoginResponse;
import com.hyy.springbootblog.service.BlogService;
import com.hyy.springbootblog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource(name="userServiceImpl")//这里填写bean的名称 也就是类名首字母小写 但如果前两位均为大写，bean的名称为类名本身
    private UserService userService;

    @PostMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginParam userLoginParam){//这里参数校验已经在UserLoginParam中实现了
            log.info("用户登录,username = {}",userLoginParam.getUsername());
            return userService.login(userLoginParam);
    }

    @PostMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId){//@NotNull来源于
        log.info("获取作者信息,userId = {}",userId);
        return userService.getUserInfo(userId);
    }


    /*
    *  //1、根据博客id 找到作者id
        //2、根据作者id 找到作者信息
*/
    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId){
        log.info("获取作者信息,blogId = {}",blogId);
        return userService.getAuthorInfo(blogId);

    }
}
